package com.lagou.jdbc03;

import com.lagou.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class TestPS {
    public static void main(String[] args) throws  Exception {
        Connection connection = JDBCUtils.getConnection();
        Statement statement=connection.createStatement();

        //向数据库插入两条数据
        int i=statement.executeUpdate("insert into jdbc_user values (null,'黄少楠','12345','2000-04-25')");
        int i1=statement.executeUpdate("insert into jdbc_user values (null,'黄少少','123456','2000-04-26')");

        //获取预处理对象
        String str1="insert into jdbc_user values(?,?,?,?)";
        PreparedStatement preparedStatement = connection.prepareStatement(str1);

        //先插入第一条数据
        preparedStatement.setObject(1,null);
        preparedStatement.setString(2,"荧光");
        preparedStatement.setString(3,"1212");
        preparedStatement.setString(4,"1999-01-01");
        //执行插入
        int a =preparedStatement.executeUpdate();

        //插入第二条数据
        preparedStatement.setObject(1,null);
        preparedStatement.setString(2,"荧狗");
        preparedStatement.setString(3,"121212");
        preparedStatement.setString(4,"1999-01-30");
        //执行插入
        int b =preparedStatement.executeUpdate();

        //释放资源
        JDBCUtils.close(connection,preparedStatement);
    }
}
